#include "stdio.h"
#include "stdlib.h"

int gcd2nums(int, int);

int main()
{
    int m, n;

    printf("please input two integers: ");
    
    scanf("%d %d", &m, &n);

    int result = gcd2nums(m, n);

    printf("the greatest common divisor of %d and %d is: %d\n", m, n, result);

    return 0;
}

// compute the greatest common divisor of m and n
int gcd2nums(int m, int n)
{
    if (m < n)
    {
        m ^= n;
        n ^= m;
        m ^= n;
    }

    int r;

    while (n != 0)
    {
        r = m % n;
        m = n;
        n = r;
    }

    return m;
}
